<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
class Welcome extends CI_Controller {

    //constructor
     function __construct()
     {           
        parent::__construct();                
     }

    public function index()
    {   
         $this->PortalLogin();
        
     }
     function testShowDocGroup()
     {
         $doc_group = Doc_group::all();
        echo '<pre>';
        print_r ($doc_group) ;
        echo '<br/>';
         
     }  
    function testLoadUser(){
        $users = User::all();
        foreach($users as $user)
        {
            echo 'username:'.$user->username.'<br/>';
        }
        echo '<pre>';
        print_r ($users) ;
        echo '<br/>';
    }
    function PortalLogin()
    {
                                                
        if ($_POST)           
        {
            $user = User::ValidateLogin($_POST['username'],$_POST['password']);
            if($user )
            {
               
                redirect('home');
            } 
            else
            {
                $this->view_data['message']='Invalid username/password';
                $this->load->view('v_login',$this->view_data);
            }
        }
        else
            $this->load->view('v_login');

    }
    function CreateUser($username,$password)
    {
        $userprofile = array('username'=>$username,
                             'password'=>$password,
                             'email'=>'eugene.ng@redtone.com',
                             'mobilephone'=>'0133800118',
                             );
        $user = User::CreateUser($userprofile);
        if ($user)
        {
            echo '<pre>';
            print_r($user);
        }
        else
            echo 'failed to create user';
        
    }
                         
}/* End of class */

?>